<template>
	<view class="bg-white h_100">
		<u-sticky>
			<view class="header px-2 py-2 bg-white"><search-view @search="searchChange" @clear="searchChange('')"></search-view></view>
		</u-sticky>
		<view v-if="listInfo.length <= 0" class="p-2 mt-3"><u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty></view>
		<view v-else class="bg-white p-2 news_box">
			<news-list :list="listInfo" :exhibitionId="exhibitionId"></news-list>
			<u-loadmore :status="status" color="#E5E5E5" lineColor="#E5E5E5" dashed line />
		</view>
	</view>
</template>

<script>
import searchView from '@/components/search/search.vue';
import { getHeavyNews } from '@/api/home/home.js';
import newsList from '@/components/news_list.vue';
// import util from '@/common/js/util.js';
export default {
	components: { searchView, newsList },
	data() {
		return {
			searchV: '',
			listInfo: [],
			page: 1,
			pageSize: 10,
			status: 'loadmore',
			suo: true,
			exhibitionId: ''
		};
	},
	// computed: {
	// 	timeDate() {
	// 		return function(val) {
	// 			return util.getDateBeforeNow(val);
	// 		};
	// 	}
	// },
	onLoad(option) {
		this.exhibitionId = option.exhibitionId;
		this.getList();
		// 分享
		wx.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		});
	},
	onReachBottom() {
		if (this.suo) {
			//定义个小锁，当没有数据时锁住suo
			this.status = 'loading';
			this.page = ++this.page;
			setTimeout(() => {
				this.getList();
			}, 1000);
		}
	},
	methods: {
		searchChange(value) {
			this.searchV = value;
			this.getList();
			this.listInfo = [];
		},
		getList(val) {
			let msg = {
				kw: decodeURIComponent(this.searchV) || '',
				page: this.page,
				pagesize: this.pageSize,
				zhanhui_id: this.exhibitionId
			};
			getHeavyNews(msg)
				.then(res => {
					if (res.code == 0) {
						this.listInfo.push(...res.data);
						if (res.data.length == 0) {
							this.status = 'nomore';
							this.suo = false;
						} else if (res.data.length < 10) {
							this.status = 'nomore';
							this.suo = false;
						} else {
							this.status = 'loadmore';
							this.suo = true;
						}
					} else {
						uni.$u.toast(res.msg);
					}
				})
				.catch(err => {
					console.log('获取重磅新闻失败');
				});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background-color: $color2;
}
.header {
	// background-color: $color14;
	// position: fixed;
	width: 100%;
}
.news_box {
	// padding-top: 80rpx;
}
</style>
